/*
 * @lc app=leetcode.cn id=69 lang=cpp
 *
 * [69] x 的平方根 
 */

// @lc code=start
class Solution {
public:

    int mySqrt(int x) {
        int l = 1, r = x; // [ )
        if (x == 0 || x == 1) return x; 
        while (r - l > 1) {
            int middle = l + (r - l + 1) / 2;
            if (middle <=  x / middle) {
                l = middle;
            } else {
                r = middle;
            }
        }
        return l;
    }

    // 1 8 1 3 2 3
};
// @lc code=end

